package com.easy.controller;

import com.easy.bean.Administrator;
import com.easy.service.ISystemLoginService;
import com.easy.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("sys")
public class SystemPageController {
    @RequestMapping("category")
    public String category(){
        return "system/category.html";
    }

    @RequestMapping("product")
    public String product(){
        return "system/product.html";
    }

    @RequestMapping("cart")
    public String cart(){
        return "system/cart.html";
    }

    @RequestMapping("receiveraddress")
    public String receiveraddress(){
        return "system/receiveraddress.html";
    }

    @RequestMapping("orders")
    public String orders(){
        return "system/orders.html";
    }

    @RequestMapping("user")
    public String user(){
        return "system/user.html";
    }

    @RequestMapping("admin")
    public String administrator(){
        return "system/administrator.html";
    }

    @RequestMapping("comment")
    public String comment(){
        return "system/comment.html";
    }

    @RequestMapping("collect")
    public String collect(){
        return "system/collect.html";
    }

    @RequestMapping("orderdetails")
    public String orderdetails(){
        return "system/orderdetails.html";
    }

    @RequestMapping("account")
    public String account(){
        return "system/my-account.html";
    }

    @RequestMapping("productimg")
    public String productimg(){
        return "system/productimg.html";
    }

    @RequestMapping("index")
    public String adminindex(){
        return "system/index.html";
    }

    @RequestMapping("login")
    public String login(){
        return "system/login.html";
    }

    @Autowired
    ISystemLoginService systemLoginService;
    @RequestMapping("dologin")
    @ResponseBody
    public String systemlogin(Administrator administrator, HttpSession session){
        if(systemLoginService.dologin(administrator)){
            session.setAttribute(SYS.SYSTEM_LOGIN_ADMIN,administrator);
            return "success";
        }else{
            return "fail";
        }
    }

    @RequestMapping("example")
    public String example(){
        return "system/example.html";
    }



}
